home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / text / edit / htmledit98.lha / HTMLEdit98 / HTMLedit.c < prev    next >
C/C++ Source or Header  |  1998-01-04  |  16KB  |  567 lines

  1. //
  2. // HTMLEditor V1.0
  3. // ---------------
  4. //
  5. // Készítette:
  6. // -----------
  7. // Klingl János      /Cyber/
  8. // Szekeres Károly   /Szeka/
  9. // 
  10. // Ez a program a Kandó Kálmán Mûszaki Fõiskola Számítógéptechnikai Intézetének
  11. // keretein belül, mint féléves Project feladat került elkészítésre.
  12. // 
  13. // Köszönetek:
  14. // -----------
  15. // Stefan Stuntz     /A MUI írójának/
  16. // Dirk Holtwick  /A HTMLtext írójának/
  17. // Allan Odgaard  /TextEditor írójának/
  18. // Eric Totel     /MUIBuilder írájának/
  19. // És minden olyan embernek, aki örömmel használja ezt a programot.
  20. //
  21.  
  22. // Szükséges include-ok beillesztése.
  23.  
  24. #include <workbench/startup.h>
  25. #include <clib/alib_protos.h>
  26. #include <proto/dos.h>
  27. #include <proto/exec.h>
  28. #include <proto/intuition.h>
  29. #include <proto/graphics.h>
  30. #include <proto/asl.h>
  31. #include <proto/utility.h>
  32. #include <proto/muimaster.h>
  33. #include <proto/icon.h>
  34. #include <stdio.h>
  35. #include <string.h>
  36. #include <stdlib.h>
  37.  
  38. #include <Rexx/Storage.h>
  39. #include <Proto/RexxSysLib.h>
  40.  
  41. // HTMLtext.mcc
  42. #include <mui/HTMLtext_mcc.h>
  43.  
  44. // TextEditor.mcc
  45. #include <MUI/TextEditor_mcc.h>
  46.  
  47. #define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
  48. #define cucc __saveds __asm
  49.  
  50. extern struct Library *SysBase;
  51. // a buttonokat valami fiktív értéktõl kezdve sorszámozzuk, hogy
  52. // késõbb meg tudjuk különböztetni õket.
  53. enum {relod_p=897,refrs_p,preview_p,save_p,new_p,fromurl_p,
  54.       h1_p,h2_p,h3_p,h4_p,h5_p,h6_p,html_p,body_p,center_p,title_p,image_p,link_p,br_p,hr_p,p_p,
  55.       };
  56. //veremméret lefixálása (HTMLtext igényli)
  57. LONG __stack = 8192;
  58.  
  59. APTR app;    //aplikáció
  60. APTR window;//ablak
  61. APTR str;    //szövegbeíró
  62. APTR html;  //html viewer
  63. APTR scroll;//és annak scroller-ja
  64. APTR url;   //url cím vagy lokális cím kijelzésének objecte
  65.  
  66. LONG cmap[8];
  67.  
  68. char empty[]="";//újrakezdés-koz ezt töltjük be.
  69.  
  70. // hiba esetén ez a változó jelzi, hogy hiba történt(texteditor használja)
  71. int error=0;
  72. // ha (error==1) igaz, akkor -> hiba történt
  73. // !!Figyelem a tesztelendõ utasítás elé kinullázás(error=0) szükséges.
  74.  
  75. /// AppMsg Funkciók a MUI-nak
  76. __saveds __asm LONG AppMsgFunc(register __a2 APTR obj, register __a1 struct AppMessage **x)
  77. {
  78.  
  79.     struct WBArg *ap;
  80.     struct AppMessage *amsg = *x;
  81.     static char buf[256];
  82.  
  83.     if(amsg->am_NumArgs)
  84.     {
  85.         ap=amsg->am_ArgList;
  86.         NameFromLock(ap->wa_Lock,buf,sizeof(buf));
  87.         AddPart(buf,ap->wa_Name,sizeof(buf));
  88.         set(obj,MUIA_HTMLtext_URL,buf);
  89.     }
  90.  
  91.     return(0);
  92. }
  93.  
  94. cucc ULONG TextEditor_Dispatcher (register __a0 struct IClass *cl, register __a2 Object *obj, register __a1 struct MUIP_TextEditor_HandleError *msg)
  95. {
  96.  
  97. // A "texteditor.mcc"-vel való kapcsolat fenntartásához szükséges
  98. // metódusok lekezelését végzõ függvények
  99.  
  100.     switch(msg->MethodID)
  101.     {
  102.         case MUIM_Show:
  103.         {
  104.                 struct ColorMap *cm = muiRenderInfo(obj)->mri_Screen->ViewPort.ColorMap;
  105.  
  106.             cmap[0] = ObtainBestPenA(cm, 0x00<<24, 0x00<<24, 0x00<<24, NULL);
  107.             cmap[1] = ObtainBestPenA(cm, 0xff<<24, 0xff<<24, 0xff<<24, NULL);
  108.             cmap[2] = ObtainBestPenA(cm, 0xff<<24, 0x00<<24, 0x00<<24, NULL);
  109.             cmap[3] = ObtainBestPenA(cm, 0x00<<24, 0xff<<24, 0x00<<24, NULL);
  110.             cmap[4] = ObtainBestPenA(cm, 0x00<<24, 0xff<<24, 0xff<<24, NULL);
  111.             cmap[5] = ObtainBestPenA(cm, 0xff<<24, 0xff<<24, 0x00<<24, NULL);
  112.             cmap[6] = ObtainBestPenA(cm, 0x00<<24, 0x00<<24, 0xff<<24, NULL);
  113.             cmap[7] = ObtainBestPenA(cm, 0xff<<24, 0x00<<24, 0xff<<24, NULL);
  114.             break;
  115.         }
  116.  
  117.         case MUIM_Hide:
  118.         {
  119.                 struct ColorMap *cm = muiRenderInfo(obj)->mri_Screen->ViewPort.ColorMap;
  120.                 int c;
  121.  
  122.             for(c = 0; c < 8; c++)
  123.             {
  124.                 if(cmap[c] >= 0)
  125.                 {
  126.                     ReleasePen(cm, cmap[c]);
  127.                 }
  128.             }
  129.             break;
  130.         }
  131.  
  132.         case MUIM_DragQuery:
  133.         {
  134.             return(TRUE);
  135.         }
  136.  
  137.         case MUIM_DragDrop:
  138.         {
  139.             break;
  140.         }
  141.  
  142.        // hibák lekezelése
  143.         case MUIM_TextEditor_HandleError:
  144.         {
  145.                 char *errortxt = NULL;
  146.             error = 1;
  147.  
  148.             switch(msg->errorcode)
  149.             {
  150.  
  151.                 case Error_ClipboardIsEmpty:
  152.                     errortxt = "\33cThe clipboard is empty.";
  153.                     break;
  154.                 case Error_ClipboardIsNotFTXT:
  155.                     errortxt = "\33cThe clipboard does not contain text.";
  156.                     break;
  157.                 case Error_MacroBufferIsFull:
  158.                     break;
  159.                 case Error_MemoryAllocationFailed:
  160.                     break;
  161.                 case Error_NoAreaMarked:
  162.                     errortxt = "\33cNo area marked.";
  163.                     break;
  164.                 case Error_NoMacroDefined:
  165.                     break;
  166.                 case Error_NothingToRedo:
  167.                     errortxt = "\33cNothing to redo.";
  168.                     break;
  169.                 case Error_NothingToUndo:
  170.                     errortxt = "\33cNothing to undo.";
  171.                     break;
  172.                 case Error_NotEnoughUndoMem:
  173.                     errortxt = "There is not enough memory\nto keep the undo buffer.\n\nThe undobuffer is lost.";
  174.                     break;
  175.                 case Error_StringNotFound:
  176.                     break;
  177.                 case Error_NoBookmarkInstalled:
  178.                     errortxt = "There is no bookmark installed!";
  179.                     break;
  180.                 case Error_BookmarkHasBeenLost:
  181.                     errortxt = "Your bookmark has unfortunately been lost.";
  182.                     break;
  183.             }
  184.             if(errortxt)
  185.             {
  186.                 MUI_Request(app, window, 0L, NULL, "Continue", errortxt);
  187.             }
  188.             break;
  189.         }
  190.     }
  191.     return(DoSuperMethodA(cl, obj, (Msg)msg));
  192. }
  193.  
  194. // a texteditor gadget mutatója
  195.  
  196. Object *editorgad=0;
  197.  
  198. // File töltése a String.Gadget-ben szereplõ helyrõl.
  199. void refresh(void)
  200. {
  201.     char *miaz;
  202.     FILE *fh;
  203.     char *fip;
  204.     int len;
  205.  
  206.     get(str,MUIA_String_Contents,&miaz);
  207.  
  208.     if (fh=fopen(miaz,"r"))
  209.     {
  210.         fseek(fh,0,SEEK_END);
  211.         len=ftell(fh);
  212.         fseek(fh,0,SEEK_SET);
  213.         fip=(char*)malloc(len+1);
  214.         fread(fip,1,len,fh);
  215.         fclose(fh);
  216.         fip[len]=0;
  217.         set(editorgad,MUIA_TextEditor_Contents,fip);
  218.         free(fip);
  219.     };
  220. }
  221.  
  222. // File mentése a String.Gadget-ben szereplõ helyre.
  223. void savefile(void)
  224. {
  225.     char *miaz;
  226.     STRPTR savetxt;
  227.     FILE *fh;
  228.  
  229.     get(str,MUIA_String_Contents,&miaz);
  230.  
  231.     savetxt = (STRPTR)DoMethod(editorgad, MUIM_TextEditor_ExportText);
  232.     if (fh=fopen(miaz,"w"))
  233.     {
  234.         fwrite(savetxt,1,strlen(savetxt),fh);
  235.         fclose(fh);
  236.     };
  237.     free(savetxt);
  238. }
  239.  
  240. // A TextEditor.Gadget-tel Arexx interface-en keresztül tudunk beszélgetni
  241. // Ez a függvény a HTML "tag"-ek behelyezését végzi
  242. // A kijelölt szöveg elõtt a "tag"-et, mögé pedig mögé pedig
  243. // a "tag" végét jelzõ "/"-est kulcsszót kell beilleszteni.
  244. // Ez úgy csinálja meg a program, hogy a CUT paranccsal a clipboard-ba helyezzük
  245. // a "tag"-elendõ szöveget, majd beírjuk a kezdõteget. Ezután PASTE segitségével
  246. // visszaírjuk az elõzõleg vágólapra(clipboard) helyezett szöveget. Aztán beillesztjük
  247. // a tagvég jelet.
  248. void puttxt(char *tx1,char *tx2)
  249. {
  250.     char buf[120];
  251.     error = 0;
  252.     DoMethod(editorgad, MUIM_TextEditor_ARexxCmd, "CUT");
  253.     if (error==0)
  254.     {
  255.      strcpy(buf,"TEXT ");
  256.      strcat(buf,tx1);
  257.      DoMethod(editorgad, MUIM_TextEditor_ARexxCmd, buf);
  258.      DoMethod(editorgad, MUIM_TextEditor_ARexxCmd, "PASTE");
  259.      strcpy(buf,"TEXT ");
  260.      strcat(buf,tx2);
  261.      DoMethod(editorgad, MUIM_TextEditor_ARexxCmd, buf);
  262.     }
  263. }
  264.  
  265. // A Mester library-ra mutató pointer. Ez tölti be a mcc-ket()
  266. // És menti vezérli az egész megjelenítést.
  267.  
  268. struct Library *MUIMasterBase;
  269.  
  270. // Main
  271. int main(int argc,char *argv[])
  272. {
  273.     char *ural;
  274.     STRPTR ptr;
  275.  
  276.    // Gobok mutatói
  277.     Object *new,*relod,*preview,*save,*h1,*h2,*h3,*h4,*h5,*h6;
  278.     Object *htmlt,*bodyt,*centert,*titlet,*fromurl,*imaget,*linkt,*brt,*hrt,*pt;
  279.  
  280.    // az editor rész deklarációja
  281.     struct    MUI_CustomClass    *editor_mcc;
  282.  
  283.     Object *slider=0;
  284.  
  285.     struct   Library *IntuitionBase;
  286.     int      ret=RETURN_ERROR;
  287.     static   const struct Hook AppMsgHook = { { NULL,NULL },(VOID *)AppMsgFunc,NULL,NULL };
  288.  
  289.     if(IntuitionBase = OpenLibrary("intuition.library", 36))
  290.     {
  291.         if(MUIMasterBase = OpenLibrary(MUIMASTER_NAME, 13))
  292.         {
  293.           if(editor_mcc = MUI_CreateCustomClass(NULL, "TextEditor.mcc", NULL, 0, (void *)TextEditor_Dispatcher))
  294.           {
  295.             ULONG signals;
  296.             BOOL running = TRUE;
  297.            // Csinálunk egy aplikációt(ez maga a program).
  298.             app = ApplicationObject,
  299.                 MUIA_Application_Title      , "HTMLEdit",
  300.                 MUIA_Application_Version    , "$VER: HTMLEdit 1.0 " __AMIGADATE__,
  301.                 MUIA_Application_Copyright  , "(C)opyright by Best Team 1998",
  302.                 MUIA_Application_Author     , "Szeka&Cyber",
  303.                 MUIA_Application_Description, "Makes creating HTML pages easily.",
  304.                 MUIA_Application_Base       , "HTMLEDIT",
  305.  
  306.                 SubWindow, window = WindowObject,
  307.                     MUIA_Window_Title, "HTMLEdit © Best Team Szeka&Cyber 1998",
  308.                     MUIA_Window_ID   , MAKE_ID('H','T','M','L'),
  309.                     MUIA_Window_UseRightBorderScroller, TRUE,
  310.                     MUIA_Window_UseBottomBorderScroller